﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using IGolovkine.AoA.BinarySerialization;
using System.Diagnostics;

namespace IGolovkine.AoA.Tcp
{
    [Serializable]
    public class TcpConnectionData : TcpConnectionMessage 
    {
        private readonly byte[] _data;

        public TcpConnectionData(CorrelationId connectionId, byte[] data) : base(connectionId)
        {
            _data = data;
        }
        
        protected TcpConnectionData(IBinaryReader reader) : base(reader) 
        {
            _data = reader.ReadByteArray();
        }

        public byte[] Data
        {
            get { return _data; }
        }

        public string StringData
        {
            get { return Encoding.Default.GetString(_data); }
        }

        public override void Serialize(IBinaryWriter writer)
        {
            base.Serialize(writer);
            writer.WriteByteArray(_data);
        }

        public override string ToString()
        {
            return string.Format("{0}: Length = {1}", this.GetType().Name, _data.Length);
        }
    }
}
